package cn.kgm.article.server.controller;

import cn.kgm.article.server.entity.ArticleInfo;
import cn.kgm.article.server.service.ArticleInfoService;
import cn.kgm.core.http.request.BaseController;
import cn.kgm.core.jackson.JsonUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * # 技术改变自己 #
 * 文章详情
 *
 * @author kappi
 * @date 2024-03-15 18:03:05
 */
@Slf4j
@SpringBootTest
class ArticleInfoTestService extends BaseController {

    @Autowired
    private ArticleInfoService articleInfoService;

    @Test
    void page() {
        IPage<ArticleInfo> page = getPage();
        LambdaQueryWrapper<ArticleInfo> wrapper = Wrappers.lambdaQuery(ArticleInfo.builder()
                .build());
        IPage<ArticleInfo> pages = articleInfoService.page(page, wrapper);
        log.info("ArticleInfoTestService::page===>{}", JsonUtil.toJson(pages.getRecords()));
    }

    @Test
    void get() {
        Long id = 1L;
        ArticleInfo articleInfo = articleInfoService.getById(id);
        log.info("ArticleInfoTestService::get===>{}", JsonUtil.toJson(articleInfo));
    }

    @Test
    void save() {
        ArticleInfo articleInfo = ArticleInfo.builder()
                .build();
        articleInfoService.save(articleInfo);
        log.info("ArticleInfoTestService::save===>{}", JsonUtil.toJson(articleInfo));
    }

    @Test
    void update() {
        ArticleInfo articleInfo = ArticleInfo.builder()
                .build();
        articleInfoService.updateById(articleInfo);
        log.info("ArticleInfoTestService::update===>{}", JsonUtil.toJson(articleInfo));
    }

    @Test
    void delete() {
        Long[] ids = new Long[]{0L};
        articleInfoService.update(Wrappers.<ArticleInfo>lambdaUpdate()
                .set(ArticleInfo::getIsDel, true)
                .in(ArticleInfo::getId, ids));
        log.info("ArticleInfoTestService::delete===>{}", JsonUtil.toJson(ids));
    }
}
